<template>
	<view class="container">
		<view class="res_tit">欢迎注册超脑智算</view>
		<view class="reg_box">
			<view class="cu-form-group">
				<image class="lg_img" src="@/static/images/ui-41/1.png"></image>
				<input data-key="nickname"  focus placeholder="输入用户昵称" v-model="nickname" />
			</view>
			<view class="cu-form-group">
				<image class="lg_img" src="@/static/images/ui-41/2.png" style="width: 42rpx;"></image>
				<input data-key="password" password focus placeholder="登录密码" v-model="password" />
			</view>
			<view class="cu-form-group">
				<image class="lg_img" src="@/static/images/ui-41/3.png"></image>
				<input data-key="repassword" password focus placeholder="确认密码" v-model="repassword" />
			</view>
			<view class="cu-form-group">
				<image class="lg_img" src="@/static/images/ui-41/4.png"></image>
				<input data-key="paypwd" password focus placeholder="提现密码" v-model="paypwd" @input="handleInput" maxlength="6"  />
			</view>
			<view class="cu-form-group">
				<image class="lg_img" src="@/static/images/ui-41/5.png"></image>
				<input data-key="repaypwd" password focus placeholder="确认提现密码" v-model="repaypwd" @input="handleInput" maxlength="6" />
			</view>
			
			<view class="cu-form-group">
				<image class="lg_img" src="@/static/images/ui-41/6.png"></image>
				<input data-key="phone" focus placeholder="输入手机号码" v-model="phone" />
			</view>
			<view class="cu-form-group">
				<image class="lg_img" src="@/static/images/ui-41/7.png" ></image>
				<input data-key="code" focus placeholder="输入验证码" v-model="code" />
				<button class="cu-btn line" style="color:#4d8efd;" @click="getCode">{{message}}</button>
			</view>
			
			<view class="cu-form-group">
				<image class="lg_img" src="@/static/images/ui-41/8.png"  style="width: 42rpx;"></image>
				<input style="color: #fff;" data-key="parentuno" focus placeholder="填写邀请码" v-model="parentuno" />
			</view>
		</view>
		<view class="submit_btn" style="padding-top: 0;">
			<button class="cu_btn" type="button" @click="doreg">注册</button>
		</view>
		<view class="text-center padding-top-xl" style="font-size: 14px; margin-top: 10px;">
			<text class="text-gray">
				已阅读并同意
				<text @click="navToUrl('/pages/help/other?type=agreement')" style="color: #62a6ed;">《用户协议》</text>
				和
				<text @click="navToUrl('/pages/help/other?type=privacy')" style="color: #62a6ed;">《隐私政策》</text>
			</text>
		</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				index: 0,
				username:"",
				nickname:"",
				phone: "",
				code:"",
				password:"",
				repassword:"",
				paypwd:"",
				repaypwd:"",
				parentuno:"",
				message: "获取验证码",
				time: this.helper.time,
				imei: "",
				oaid:"",
				uniqid:"",
			};
		},
		onLoad: function (option) {
			if(option.invite){
				this.parentuno = option.invite;
			}

		},
		methods: {
			handleInput(event) {
			  const value = event.detail.value;
			  // 移除非数字字符
			  if (/\D/.test(value)) {
				event.detail.value = value.replace(/\D/g, '');
				}
			},
			daojishi() {
				let eventinterval = setInterval(() => {
					this.message = this.time-- + "秒";
					if (this.time <= 0) {
						clearInterval(eventinterval);
						this.message = "获取验证码";
					}
				}, 1000);
			},
			getCode() {
				if(this.phone == ''){
					uni.showToast({
						title:"请输入手机号",
						icon:"none"
					})
					return;
				}
				if (this.message != "获取验证码") {
					return;
				}
				//短信验证码的获取
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(["phone=" + this.phone, "type=reg","timestamp=" + timestamp]);
				this.helper.req({
					api:"getcode",
					timestamp:timestamp,
					data:{
						phone: this.phone,
						type:'reg'
					},
					header:{
						sign: sign
					}
				}).then(res=>{
					if (this.message == "获取验证码") {
						this.uniqid= res.data.data.uniqid;
						this.time = this.helper.time;
						this.daojishi();
					}
				});
			},
			doreg() {
				let that = this;
				if(this.phone == ''){
					uni.showToast({
						title:"请输入手机号",
						icon:"none"
					})
					return;
				}
				if(this.nickname == ''){
					uni.showToast({
						title:"请输入用户昵称",
						icon:"none"
					})
					return;
				}				
				if(this.password == ''){
					uni.showToast({
						title:"请输入密码",
						icon:"none"
					})
					return;
				}
				if(this.repassword == ''){
					uni.showToast({
						title:"请输入确认密码",
						icon:"none"
					})
					return;
				}
				if(this.code == ''){
					uni.showToast({
						title:"请输入验证码",
						icon:"none"
					})
					return;
				}
				if(this.parentuno == ''){
					uni.showToast({
						title:"请输入邀请码",
						icon:"none"
					})
					return;
				}
				let timestamp = this.helper.now();
				let sign = this.helper.setSign(["imei=" + this.imei,"oaid=" + this.oaid,'uniqid='+this.uniqid,'code='+this.code,'username='+this.phone,'nickname='+this.nickname,'phone='+this.phone,'parentuno='+this.parentuno,'password='+this.password,'repassword='+this.repassword,'paypwd='+this.paypwd,'repaypwd='+this.repaypwd,'timestamp='+timestamp]);
				this.helper.req({
					api:"reg",
					timestamp:timestamp,
					data:{
						imei:this.imei,
						oaid:this.oaid,
						uniqid:this.uniqid,
						username:this.phone,
						nickname:this.nickname,
						phone:this.phone,
						code:this.code,
						password:this.password,
						repassword:this.repassword,
						paypwd:this.paypwd,
						repaypwd:this.repaypwd,
						parentuno:this.parentuno,
					},
					header:{
						sign: sign
					}
				}).then(res=>{

					//注册成功
					uni.showToast({
						title: "注册成功",
						icon: "none",
						position: "bottom",
						success: () => {
							setTimeout(()=>{
								uni.navigateTo({
									url:"/pages/login/login"
								});
							},1000)
						}
					})
				});
			},
			// 链接
			navToUrl:function(url){
				uni.navigateTo({
					url: url,
				});	
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ddeafd;
		color: #56595d;
	}
	.res_tit{
		line-height: 120rpx;
		color:#508ffd;
		font-size: 20px;
		text-align: center;
	}
	.reg_box{
		background: #ffffff;
		margin: 0 5vw 10vw 5vw;
		border-radius: 10px;
	}
	.reg_title{
		font-size: 50upx;
		padding: 20upx;
	}
	.cu-form-group{
		padding: 0 40rpx;
		input{
			padding: 4px 20px;
			line-height: 30px;
			height: 30px;
		}
		image{
			width: 20px;
			height: 20px;
		}
	}
	.cu-form-group .title {
		min-width: 200upx;
	}
	.logo{
		padding: 80px 0 50px;
		text-align: center;
		image{
			width: 80px;
			height: 80px;
		}
	}
	.lg_img{
		width: 48rpx;
		height: 48rpx;
	}
	.cu_btn{
		background: linear-gradient( 180deg, #9dc1ff 0%, #508ffd 100%);
		height: 50px;
		width: 80vw;
		color: #fff;
		line-height: 50px;
		font-size: 16px;
		border-radius: 30px;
	}
</style>
